﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Skywave.Linq;

namespace Skywave.DataStructure
{
    public class ListHelper<T>
    {
        public ListHelper()
        {
            _Source = new List<T>();
        }
        public ListHelper(IEnumerable<T> source)
        {
            _Source = source.ToList();
        }
        public ListHelper(List<T> source)
        {
            _Source = source;
        }

        private List<T> _Source;
        /// <summary>
        /// Source Property
        /// </summary>
        public List<T> Source
        {
            get { return _Source; }
            set { _Source = value; }
        }

        public string ToSeperated()
        { return ToSeperated(','); }
        public string ToSeperated(char seperator, bool removeNullOrEmpty = false)
        {
            string r = "";
            if (_Source != null)
            {
                string str1;
                foreach (T fe1 in _Source)
                {
                    str1 = fe1.ToString();
                    if (!removeNullOrEmpty || !string.IsNullOrEmpty(str1))
                        r += str1 + seperator;
                }
            }
            r = r.Trim(new char[] { ' ', seperator });
            return r;
        }
        public string ToSeperated(string seperator, bool removeNullOrEmpty = false)
        {
            return _Source.ToSeperated(seperator, removeNullOrEmpty);
        }
    }
}
